div.container
  h1 Settings
  h2 Arduino
  p Example Wirings:&nbsp;
    a(href="http://ni-c.github.com/heimcontrol.js/plugins/arduino.html") http://ni-c.github.com/heimcontrol.js/plugins/arduino.html
  - if (typeof(success) !== 'undefined')
    div.alert.alert-success.fade.in
      button.close(type="button", data-dismiss="alert") ×
      =success
  div.row16
    form(action="/settings/arduino", method="post")
      div#arduino
        each item, i in items
          div.plugin-container.arduino.settings(id="#{item._id}")
            button.btn.btn-danger.pull-right.delete(type="button",data-delete="#{item._id}")
              i.icon-trash.icon-large
              |  Delete
            label(for="description") Description (optional):
            input(type="text", name="data[#{i}][description]", placeholder="Temperature", value="#{item.description}")
            label(for="pin") Arduino PIN:
            input.uppercase(type="text", name="data[#{i}][pin]", placeholder="10", maxlength="2", required="1", value="#{item.pin}", pattern="^A[0-9]|[0-9]{1,2}$")
            div.switch
              label(for="method") Method:
              select(name="data[#{i}][method]")
                option(disabled="disabled", selected=(item.method == ''))         Choose Method
                option(value="rcswitch",    selected=(item.method == 'rcswitch')) RC switch
                option(value="sensor",      selected=(item.method == 'sensor'))   sensor
                option(value="irremote",    selected=(item.method == 'irremote')) IR remote
                option(value="led",         selected=(item.method == 'led'))      LED
              div.switch-container

                div.rcswitch(class=(item.method != 'rcswitch' ? 'hidden' : ''))
                  div.switch
                    label(for="rctype") RC code type:
                    select(name="data[#{i}][rctype]")
                      option(value="tristate", selected=(item.rctype != 'binary')) Tri-state
                      option(value="binary",   selected=(item.rctype == 'binary')) Binary
                    div.switch-container.no-clear-on-switch
                      div.tristate(class=(item.rctype == 'binary' ? 'hidden' : ''))
                        label(for="code") Tri-state code (without suffix):
                        input.uppercase(type="text", name="data[#{i}][code]", placeholder="FF0F0FFF", data-required="1", maxlength="10", value=(item.code ? item.code : ''), pattern="^[A-Fa-f0-9]{8,10}$")
                        label(for="onsuffix") <code>on</code> suffix:
                        input.uppercase(type="text", name="data[#{i}][onsuffix]", placeholder="FF0F", data-required="1", maxlength="4", value=(item.onsuffix ? item.onsuffix : 'FF0F'), pattern="^[A-Fa-f0-9]{2,4}$")
                        label(for="offsuffix") <code>off</code> suffix:
                        input.uppercase(type="text", name="data[#{i}][offsuffix]", placeholder="FF00", data-required="1", maxlength="4", value=(item.offsuffix ? item.offsuffix : 'FF00'), pattern="^[A-Fa-f0-9]{2,4}$")
                      div.binary(class=(item.rctype != 'binary' ? 'hidden' : ''))
                        label(for="binaryOn") Binary <code>on</code> code:
                        input(type="text", name="data[#{i}][binaryOn]", placeholder="", data-required="0", maxlength="24", value=(item.binaryOn ? item.binaryOn : ''), pattern="^[01]{24}$")
                        label(for="binaryOff") Binary <code>off</code> code:
                        input(type="text", name="data[#{i}][binaryOff]", placeholder="", data-required="0", maxlength="24", value=(item.binaryOff ? item.binaryOff : ''), pattern="^[01]{24}$")

                div.sensor(class=(item.method != 'sensor' ? 'hidden' : ''))
                  label(for="formula") Formula
                  input(type="text", name="data[#{i}][formula]", placeholder="x*100-3.14", data-required="1", value=(item.formula ? item.formula : ''))
                  label(for="unit") Unit (optional):
                  input(type="text", name="data[#{i}][unit]", placeholder="°F", data-required="0", value=(item.unit ? item.unit : ''))
                div.irremote(class=(item.method != 'irremote' ? 'hidden' : ''))
                  label(for="irtype") IR Type:
                  select(name="data[#{i}][irtype]")
                    option(disabled="disabled",selected=(item.irtype == '')) Choose Type
                    option(value="1",selected=(item.irtype == '1')) RC5
                    option(value="2",selected=(item.irtype == '2')) RC6
                    option(value="3",selected=(item.irtype == '3')) NEC
                    option(value="4",selected=(item.irtype == '4')) Sony
                    option(value="5",selected=(item.irtype == '5')) DISH
                    option(value="6",selected=(item.irtype == '6')) Sharp
                    option(value="7",selected=(item.irtype == '7')) Panasonic
                    option(value="8",selected=(item.irtype == '8')) JVC
                  label(for="ircode") Code:
                  input.uppercase(type="text", name="data[#{i}][ircode]", placeholder="F0F2A3A2", data-required="1", value=(item.ircode ? item.ircode : ''), pattern="^[A-F0-9]*$")
                  label(for="addr") Length:
                  input(type="text", name="data[#{i}][irlength]", placeholder="48", data-required="1", value=(item.irlength ? item.irlength : ''))

            input(type="hidden", name="data[#{i}][_id]", value="#{item._id}")
            input(type="hidden", name="data[#{i}][status]", value="#{item.status}")
          
      p.arduino.buttons
        button.btn.btn-info.add(data-target="arduino", type="button", data-callback="registerSelectSwitch()") 
          i.icon-plus.icon-large
          |  Add
      
        button.btn.btn-success.save(type="submit") 
          i.icon-save.icon-large
          |  Save
          
input(type="hidden", name="iterator", id="iterator", value=(items.length))

div.plugin-container.arduino.settings#template(style="display: none;")
  button.btn.btn-danger.pull-right.delete(type="button")
    i.icon-trash.icon-large
    |  Delete
  label(for="description") Description (optional):
  input(type="text", name="data[%i%][description]", placeholder="Temperature")
  label(for="pin") Arduino PIN:
  input.uppercase(type="text", name="data[%i%][pin]", placeholder="10", maxlength="2", required="1", pattern="^A[0-9]|[0-9]{1,2}$")
  div.switch
    label(for="method") Method:
    select(name="data[%i%][method]")
      option(disabled="disabled", selected=true) Choose Method
      option(value="rcswitch") RC switch
      option(value="sensor") sensor
      option(value="irremote") IR remote
      option(value="led") LED
    div.switch-container

      div.rcswitch.hidden
        div.switch
          label(for="rctype") Choose RC code type:
          select(name="data[%i%][rctype]")
            option(value="tristate",selected=true) Tri-state
            option(value="binary") Binary
          div.switch-container.no-clear-on-switch
            div.tristate
              label(for="code") Tri-state code (without suffix):
              input.uppercase(type="text", name="data[%i%][code]", maxlength="10", placeholder="FF0F0FFF", data-required="1", pattern="^[A-F0-9]{8,10}$")
              label(for="onsuffix") <code>on</code> suffix:
              input.uppercase(type="text", name="data[%i%][onsuffix]", maxlength="4", placeholder="FF0F", data-required="1", pattern="^[A-Fa-f0-9]{2,4}$")
              label(for="offsuffix") <code>off</code> suffix:
              input.uppercase(type="text", name="data[%i%][offsuffix]", maxlength="4", placeholder="FF00", data-required="1", pattern="^[A-Fa-f0-9]{2,4}$")
            div.binary.hidden
              p Enter the <code>on</code> and <code>off</code> codes separately as binary codes. Length is currently hardcoded at 24 bits, but this could be changed if the need arises.
              label(for="binaryOn") Binary <code>on</code> code:
              input(type="text", name="data[%i%][binaryOn]", placeholder="", data-required="0", maxlength="24", pattern="^[01]{24}$")
              label(for="binaryOff") Binary <code>off</code> code:
              input(type="text", name="data[%i%][binaryOff]", placeholder="", data-required="0", maxlength="24", pattern="^[01]{24}$")
      
      div.sensor.hidden
        label(for="formula") Formula:
        input(type="text", name="data[%i%][formula]", placeholder="x*3.14-100", data-required="1")
        label(for="unit") Unit (optional):
        input(type="text", name="data[%i%][unit]", placeholder="°F", data-required="0")
      
      div.irremote.hidden
        label(for="irtype") IR Type:
        select(name="data[%i%][irtype]")
          option(disabled="disabled", selected=true) Choose Type
          option(value="1") RC5
          option(value="2") RC6
          option(value="3") NEC
          option(value="4") Sony
          option(value="5") DISH
          option(value="6") Sharp
          option(value="7") Panasonic
          option(value="8") JVC
        label(for="ircode") Code:
        input.uppercase(type="text", name="data[%i%][ircode]", placeholder="F0F2A3A2", data-required="1", pattern="^[A-F0-9]*$")
        label(for="addr") Length:
        input(type="text", name="data[%i%][irlength]", placeholder="48", data-required="1")

    input(type="hidden", name="data[%i%][status]", value="0")
